package me.wangqu.weiyouqu.web.rest;

import com.codahale.metrics.annotation.Timed;
import me.wangqu.weiyouqu.web.rest.business.model.RankModel;
import me.wangqu.weiyouqu.web.rest.business.service.RanklistService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RestController;

import java.net.URISyntaxException;
import java.util.List;

/**
 * REST controller for managing Ranklist.
 */
@RestController
@RequestMapping("/api")
public class RanklistResource {

    private final Logger log = LoggerFactory.getLogger(RanklistResource.class);
    @Autowired
    private RanklistService ranklistService;

    /**
     * GET  /ranklists : 获取排行榜列表
     *
     * @return the ResponseEntity with status 200 (OK) and the list of ranklists in body
     * @throws URISyntaxException if there is an error to generate the pagination HTTP headers
     */
    @RequestMapping(value = "/ranklists",
        method = RequestMethod.GET,
        produces = MediaType.APPLICATION_JSON_VALUE)
    @Timed
    @Transactional(readOnly = true)
    public ResponseEntity<List<RankModel>> getAllRanklists()
        throws URISyntaxException {
        log.debug("获取排行榜");
        return new ResponseEntity<>(ranklistService.getAllRanklists(), HttpStatus.OK);

    }

}
